﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using CuteSprite.Eme.Client;
using CuteSprite.Eme.Data;
using CuteSprite.Eme.Data.BsdUserCenter;
using CuteSprite.Eme.Data.CRM;
using CuteSprite.Eme.Data.Testing;
using CuteSprite.Eme.MIS.Client;
using CuteSprite.Eme.UI.Utils;
using HmFramework.Components;
using HmFramework.Components.Controls;
using HmFramework.Components.Editors.DateTimeAdv;
using HmFramework.Data;
using HmFramework.Data.Configuration;
using HmFramework.Log;
using HmFramework.Text;
using HmFramework.UI.Utils;
using HmFramework.UI.Utils.Controls;
using HmFramework.Reflection;
using HmFramework.Threading;


namespace CuteSprite.Eme.UI.Test
{
	public partial class FrmTest005 : EmeEntityForm
	{

		#region -- Fields --
		private Test005 _CurrentExpressEntity;
		#endregion

		#region -- 构造 --

		#region - 新增 -

		/// <summary>默认构造函数</summary>
		public FrmTest005()
			: base()
		{
			InitializeComponent();
			InitForm();
		}

		/// <summary>构造函数</summary>
		/// <param name="templateFileName">模板文件</param>
		public FrmTest005(String templateFileName)
		{
			SetupFromXml(templateFileName);
			InitForm();
		}

		/// <summary>构造函数</summary>
		/// <param name="resourceName">模板资源文件</param>
		/// <param name="asm">模板资源文件所在程序集</param>
		public FrmTest005(String resourceName, Assembly asm)
		{
			SetupFromXmlResource(resourceName, asm);
			InitForm();
		}

		/// <summary>构造函数</summary>
		/// <param name="stream">模板数据流</param>
		public FrmTest005(Stream stream)
		{
			SetupFromXmlStream(stream);
			InitForm();
		}

		#endregion

		#region - 编辑或新增 -

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		public FrmTest005(IEntity entity)
			: this(entity, false)
		{
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="readOnly">是否只读，指定编辑还是浏览实体信息</param>
		public FrmTest005(IEntity entity, Boolean readOnly)
			: base(entity, readOnly)
		{
			InitializeComponent();
			InitForm();
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="templateFileName">模板文件</param>
		public FrmTest005(IEntity entity, String templateFileName)
			: this(entity, templateFileName, false)
		{
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="templateFileName">模板文件</param>
		/// <param name="readOnly">是否只读，指定编辑还是浏览实体信息</param>
		public FrmTest005(IEntity entity, String templateFileName, Boolean readOnly)
			: base(entity, readOnly)
		{
			SetupFromXml(templateFileName);

			InitForm();
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="resourceName">模板资源文件</param>
		/// <param name="asm">模板资源文件所在程序集</param>
		public FrmTest005(IEntity entity, String resourceName, Assembly asm)
			: this(entity, resourceName, asm, false)
		{
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="resourceName">模板资源文件</param>
		/// <param name="asm">模板资源文件所在程序集</param>
		/// <param name="readOnly">是否只读，指定编辑还是浏览实体信息</param>
		public FrmTest005(IEntity entity, String resourceName, Assembly asm, Boolean readOnly)
			: base(entity, readOnly)
		{
			SetupFromXmlResource(resourceName, asm);

			InitForm();
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="stream">模板数据流</param>
		public FrmTest005(IEntity entity, Stream stream)
			: this(entity, stream, false)
		{
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="stream">模板数据流</param>
		/// <param name="readOnly">是否只读，指定编辑还是浏览实体信息</param>
		public FrmTest005(IEntity entity, Stream stream, Boolean readOnly)
			: base(entity, readOnly)
		{
			SetupFromXmlStream(stream);

			InitForm();
		}

		#endregion

		#endregion


		#region -- 属性 --

		private EmeBsdMisManagement _BsdMisManagement = null;

		/// <summary>BsdMIS客户端管理</summary>
		protected EmeBsdMisManagement BsdMisManagement
		{
			get
			{
				if (_BsdMisManagement == null) { _BsdMisManagement = ServerManagement as EmeBsdMisManagement; }
				return _BsdMisManagement;
			}
		}

		private int MaxMultiSelectNumber { get; set; }

		private bool Ifvalid { get; set; }
	
		#endregion

		#region -- 窗体事件 --

		#region - method InitComponent -

		/// <summary>控件初始化</summary>
		protected override void InitComponent()
		{
			base.InitComponent();

			if (frmSelectID == null)
			{
				frmSelectID = FindControl("frmSelectID") as EntitySelector;
			}

			MaxMultiSelectNumber = 1;
			//MessageBox.Show("这个"+"InitComponent()");

			this.OnValid += new System.EventHandler<CuteSprite.Eme.UI.Utils.EntityFormEventArgs>(this.FrmTest005_OnValid);
			this.OnSaving += new System.EventHandler<CuteSprite.Eme.UI.Utils.EntityFormEventArgs>(this.FrmTest005_OnSaving);
			//this.OnSaveSuccess += new System.EventHandler<CuteSprite.Eme.UI.Utils.EntityFormEventArgs>(this.FrmExpress_OnSaveSuccess);
		}

		#endregion

		#region - method FormOnLoad -


		public override void FormOnLoad()
		{
			
			base.FormOnLoad();
			//AcceptButton 
			this.AcceptButton = FindControl("btnSave") as IButtonControl;
			MaxMultiSelectNumber = 2;

			//
		}

		#endregion

		#region - method FormOnPreLoad -

		protected override void FormOnPreLoad()
		{
			base.FormOnPreLoad();

			//MessageBox.Show("这个" + "FormOnPreLoad()");

			//MyListBoxItems mylistitems = new MyListBoxItems("这是一个测试项，值为100", 100);
			//CheckBoxX cbx = new CheckBoxX();
			//cbx.Text = "这是一个测试项，值为100";
			//cbx.Tag = 100;
			//flpSelect.Controls.Add(cbx);

			//CheckBox cb = new CheckBox();
			//cb.Text = "这是一个测试项2，值为200";
			//cb.Tag = 200;
			//flpSelect.Controls.Add(cb);
		}
		#endregion

		#region - method InitCurrentEntityWhenNewAdd -

		protected override void InitCurrentEntityWhenNewAdd()
		{
			base.InitCurrentEntityWhenNewAdd();
			//MessageBox.Show("这个" + "InitCurrentEntityWhenNewAdd()");
			_CurrentExpressEntity = CurrentEntity as Test005;

			//_CurrentExpressEntity.Name = string.Format("哈哈，我是" + "默认的");
		}
		#endregion
		

		#region - method FormOnShown -

		public override void FormOnShown()
		{
			base.FormOnShown();
			//MessageBox.Show("这个" + " FormOnShown()");
		
		
		}

		#endregion

		#region - 刷新窗体 -

		public override void ResetForm()
		{
		
		}

		private void RefreshFieldControls()
		{
			
		}

		#endregion

		#region - 实体保存 -

		private void FrmTest005_OnSaving(object sender, EntityFormEventArgs e)
		{
			//MessageBox.Show(frmSelectID_.SelectedIDs);
			if (!Ifvalid)
			{
				e.Cancel = true;
				return	;
			}
		

			var UserName = BsdMisManagement.CurrentUser.Name;

			var FriendName = BsdMisManagement.CurrentUser.FriendName;
			//_CurrentExpressEntity.Name = "傻傻不懂爱";
			_CurrentExpressEntity.Name = FriendName;
			//var Name=


		}

		#endregion

		#region - 实体验证 -

		private void FrmTest005_OnValid(object sender, EntityFormEventArgs e)
		{
			Ifvalid = false;
			if (frmSelectID != null)
			{
				string[] str = frmSelectID.SelectedIDs.Split(",");
				if (str == null||str.Length==0)
				{
					MessageBox.Show("投票项不能为空！");
					e.Cancel = true;
					frmSelectID.Focus();
					return;
				}else if(str.Length > MaxMultiSelectNumber)
				{
					MessageBox.Show("最多选择" + MaxMultiSelectNumber + "项");
					e.Cancel = true;
					frmSelectID.Focus();
					return;
				}
				Ifvalid = true;
			}
		}

		#endregion

		#region - 实体保存成功 -

		private String m_recStaffValue;


		private void FrmExpress_OnSaveSuccess(object sender, EntityFormEventArgs e)
		{
			
		}

		#endregion

		#endregion

		#region -- 控件事件 --
		 //private override void oncl
		private void CheckBox_CheckChange(object sender, EventArgs e)
		{
			string selectid = "";
			//check
			//foreach (CheckBox mylist in flpSelect.Controls)
			//{
			//	CheckBoxX cbx = mylist as CheckBoxX;
			//	if(selectid=="")
			//	{
			//		selectid += mylist.Tag.ToString();
			//	}else
			//	{
			//		selectid += "," + mylist.Tag.ToString();
			//	}
			//}
			//SelectedIDs=selectid;

			//MessageBox.Show(SelectedIDs.ToString());
		}

		#endregion

		#region -- 辅助 --

	
		#endregion
	}

 public	class MyListBoxItems
	{
		public  MyListBoxItems(string Text,int Value)
		{
			text = Text;
			value = Value;
		}
		public string text { get; set; }
		public int value { get; set; }

		public override string ToString()
		{
			return this.text;
		}
	}
}
